﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Bll.IObjectBlls;
using CSP.Model.CSP;
using CSP.Bll.CommonBll;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Dao;

namespace CSP.Bll.ObjectBlls
{
    public class CollectBusinessInfoBll :CSPCommonBll, ICollectBusinessInfoBll
    {
        private ICollectBusinessInfoDao _collectBusinessInfoDao;
        public CollectBusinessInfoBll()
        {

            _collectBusinessInfoDao = CSPDaoFactory.GetInstance().GetCollectBusinessInfoDao();
        }


        public CollectBusinessInfo GetDataById(int id)
        {
            CollectBusinessInfo collectBusinessInfo =_collectBusinessInfoDao.GetDataById(id);
            return collectBusinessInfo;
        }

        public ICollection<CollectBusinessInfo> GeDatatByIds(int[] Ids)
        {
            ICollection<CollectBusinessInfo> result = _collectBusinessInfoDao.GeDatatByIds(Ids);
            return result;
        }

        public void Add(CollectBusinessInfo obj)
        {
            _collectBusinessInfoDao.Add(obj);

        }

        public void Update(CollectBusinessInfo obj)
        {

            CollectBusinessInfo collectBusinessInfo = _collectBusinessInfoDao.GetDataById(obj.id);
            collectBusinessInfo.Mobile = obj.Mobile;
            collectBusinessInfo.Name = obj.Name;
            collectBusinessInfo.Phone = obj.Phone;
            collectBusinessInfo.Reason = obj.Reason;
            collectBusinessInfo.Remark = obj.Reason;
            collectBusinessInfo.Status = obj.Status;
            collectBusinessInfo.Address = obj.Address;
            collectBusinessInfo.Bonus = obj.Bonus;
            _collectBusinessInfoDao.Update(collectBusinessInfo);
        }

        public void DeleteById(int id)
        {
            _collectBusinessInfoDao.DeleteById(id);
        }

      
    
        public List<int>  FindIdsByNameAndUserName(string name, string userName)
        {
 	        List<int> result=_collectBusinessInfoDao.FindIdsByNameAndUserName(name,userName);
            return result;
        }

        public List<int>  FindIdsByName(string name)
        {
 	        List<int> result=_collectBusinessInfoDao.FindIdsByName(name);
            return result;
        }

        public List<int>  FindIdsByStatusAndUserName(Model.CSPEnum.CollectBusinessInfoStatus status, string userName)
        {
 	        List<int> result=_collectBusinessInfoDao.FindIdsByStatusAndUserName(status,userName);
            return result;
        }

        public List<int>  FindIdsByUserName(string userName)
        {
 	        List<int> result=_collectBusinessInfoDao.FindIdsByUserName(userName);
            return result;
        }

        public ICollection<CollectBusinessInfo> FindByIdsAndPageIndexAndPageSize(List<int> ids, int pageIndex, int pageSize)
        {
            List<int> requestIds = ids.Skip(pageIndex * pageSize).Take(pageSize).ToList();
            ICollection<CollectBusinessInfo> result = _collectBusinessInfoDao.GeDatatByIds(requestIds.ToArray());
            return result;
        }


        public CollectBusinessInfo DeleteByIdAndUser(int id, string userName)
        {
            CollectBusinessInfo result = _collectBusinessInfoDao.GetDataById(id);

            if (result != null && result.UserName == userName)
            {
                return result;
            }

            return result;
        }

        public void RefreshCache()
        {
            throw new NotImplementedException();
        }


    }
}
